﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using weikebuluo.DAL;
using weikebuluo.Model;
using weikebuluo.Common;

namespace weikeweixin.web.admin.order
{
    public partial class foodclassadd : weikeweixin.web.admin.cs.adminbase
    {
        a_foodclass_dal foodclassdal = new a_foodclass_dal();
        protected a_foodclass_model foodclassmodel = new a_foodclass_model();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                foodclassmodel = foodclassdal.GetModel(int.Parse(Request.QueryString["id"]));
            }
            switch (Request.Form["action"])
            {
                case "add":
                    add();
                    break;
            }
        }
        private void add()
        {
            if (!string.IsNullOrEmpty(Request.Form["id"]))
            {
                foodclassmodel = foodclassdal.GetModel(int.Parse(Request.Form["id"]));
            }
            foodclassmodel.foodclass_name = Request.Form["foodclass_name"].Trim().ToString();
            foodclassmodel.store_id = int.Parse(user_id);
            foodclassmodel.foodclass_sort = int.Parse(Request.Form["foodclass_sort"].Trim().ToString());
            if (!string.IsNullOrEmpty(Request.Form["id"]))
            {
                bool re = foodclassdal.Update(foodclassmodel);
                if (re)
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存成功！\",\"url\":\"foodclass.aspx\",\"error\":\"\"}");
                }
                else
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存失败！\",\"url\":\"foodclassadd.aspx\",\"error\":\"\"}");
                }
                Response.End();
            }
            else
            {
                foodclassmodel.foodclass_addtime = DateTime.Now;
                int re = foodclassdal.Add(foodclassmodel);
                if (re > 0)
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存成功！\",\"url\":\"foodclass.aspx\",\"error\":\"\"}");
                }
                else
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存失败！\",\"url\":\"foodclassadd.aspx\",\"error\":\"\"}");
                }

                Response.End();
            }
        }

    }

}